// tslint:disable
import { Component, Input, OnInit } from '@angular/core';
import { Platform, ModalController } from '@ionic/angular';
import { HttpService } from 'src/app/shared/service/http.service';
import { PageModalService } from 'src/app/shared/service/page-modal-service';
import { AppGlobalService } from 'src/app/shared/service/app-global.service';
import { EventService } from 'src/app/shared/service/event.service';
import { MapBaiduService } from 'src/app/shared/service/map.baiduapi';
import AddressParse from 'address-parse';

@Component({
  selector: 'app-select-specifications',
  templateUrl: './select-specifications.component.html',
  styleUrls: ['./select-specifications.component.scss'],
})
export class SelectSpecificationsComponent implements OnInit {

  @Input() tagData;
  currentMoney: any;
  orginalMoney: any;
  postNumber: any;
  inputReadOnly = false;
  disableSub = false;
  disableAdd = false;
  currentId: any;
  currentLabel: any;
  currentCount: any;
  currentMethod: any;
  currentMethodLabel: any;
  economicalMoney: any;

  goods_inventory: any;
  goods_brand_name: any;
  spec_name: any;
  cost_price: any;
  price: any;
  pic_url: any;
  minCount = 1; // 起购量
  minBatchCount = 1; // 起批量
  numberMax = 99;

  footBtnLabel = "确定";
  enableCheckDeliveryAmount = false; // 2024.06.27 开启检查起送金额
  showCheckDeliveryAmountBtn = false; // 2024.06.27 是否显示检查起送金额
  deliveryAmount: any; // 2024.06.27 起送金额
  checkDeliveryAmountBtnLabel = '未达到起送价格';// 2024.06.27
  checkDeliveryAmountBtnCssStyle = 'XXX';// 2024.06.27
  isNumberInputDisabled = false; // 2024.03.20 控制shu
  constructor(
    private modalController: ModalController,
    private http: HttpService,
    private eventService: EventService,
    private appGlobalService: AppGlobalService,
    private pageModalService: PageModalService,
    private baiduApiService: MapBaiduService
  ) { }

  ngOnInit() {
    this.currentMoney = 0;
    this.orginalMoney = 0;
    this.postNumber = 0;

    if (this.tagData.data.data.length > 0) {

      let selectId = 0;
      for (let index = 0; index < this.tagData.data.data.length; index++) {
        const ele = this.tagData.data.data[index];
        if (ele && ele.firstRowLeft.selected) {
          if (selectId >= 1) {
            ele.firstRowLeft.selected = false;
          } else {
            this.currentId = ele.id;
            this.currentLabel = ele.label;
            this.currentMoney = ele.firstRowLeft.price;
            this.orginalMoney = ele.firstRowLeft.oldPrice;
            document.getElementById('specilIcon').setAttribute('src', ele.firstRowLeft.img);
          }
          selectId = selectId + 1;
          this.postNumber = 1;
        }
      }

      //2023.12.23 
      if (selectId === 0) {
        const ele = this.tagData.data.data[0];
        if (ele) {
          ele.firstRowLeft.selected = true;
          this.currentId = ele.id;
          this.currentLabel = ele.label;
          this.currentMoney = ele.firstRowLeft.price;
          this.orginalMoney = ele.firstRowLeft.oldPrice;
          document.getElementById('specilIcon').setAttribute('src', ele.firstRowLeft.img);
        }
      }

      this.goods_inventory = "";
      this.goods_brand_name = "";
      this.spec_name = "";
      this.cost_price = "";
      this.price = "";
      this.pic_url = "";

      if (this.tagData && this.tagData.data
        && this.tagData.data.footDiv
        && this.tagData.data.footDiv.methodBox) {



        // 2023.12.22 只有确认json里面没有配置才选中
        for (let index = 0; index < this.tagData.data.data.length; index++) {
          const ele = this.tagData.data.data[index];
          if (ele.firstRowLeft.selected === undefined) {
            ele.firstRowLeft.selected = false;
          } else if (ele.firstRowLeft.selected === true) {
            this.currentMoney = ele.firstRowLeft.price;
            this.orginalMoney = ele.firstRowLeft.oldPrice;
            this.currentId = ele.id;
            this.currentLabel = ele.label;
            if (ele.firstRowLeft.goods_inventory !== undefined) {
              this.goods_inventory = ele.firstRowLeft.goods_inventory;
            }
            if (ele.firstRowLeft.pic_url !== undefined) {
              this.pic_url = ele.firstRowLeft.pic_url;
            }
            if (ele.firstRowLeft.spec_name !== undefined) {
              this.spec_name = ele.firstRowLeft.spec_name;
            }
            if (ele.firstRowLeft.goods_brand_name !== undefined) {
              this.goods_brand_name = ele.firstRowLeft.goods_brand_name;
            }
            if (ele.firstRowLeft.price !== undefined) {
              this.price = ele.firstRowLeft.price;
            }
            if (ele.firstRowLeft.cost_price !== undefined) {
              this.cost_price = ele.firstRowLeft.cost_price;
            }
            document.getElementById('specilIcon').setAttribute('src', ele.firstRowLeft.img);
          }
        }

        this.postNumber = 1;

        if (this.tagData.data.data[0].minCount && this.tagData.data.data[0].minCount > 0) {
          this.postNumber = Number(this.tagData.data.data[0].minCount);
          this.minCount = this.postNumber;
          this.disableSub = false;
        }
        if (this.tagData.data.data[0].minBatchCount) {
          this.minBatchCount = Number(this.tagData.data.data[0].minBatchCount);
        }
        // 市场价 减去 拿货价   计算省多少钱
        if (this.tagData.data.footDiv.methodBox.commodityPrice && this.orginalMoney !== undefined && this.currentMoney !== undefined) {
          this.economicalMoney = (parseFloat(this.orginalMoney) - parseFloat(this.currentMoney)).toFixed(2);
        }
        // 计算利润
        if (this.tagData.data.footDiv.methodBox.profit && this.orginalMoney !== undefined && this.currentMoney !== undefined) {
          this.economicalMoney = (parseFloat(this.currentMoney) - parseFloat(this.orginalMoney)).toFixed(2);
        }

        if (this.tagData.data.footDiv.methodBox.enableCheckDeliveryAmount) {
          this.enableCheckDeliveryAmount = this.tagData.data.footDiv.methodBox.enableCheckDeliveryAmount;
        }

        if (this.tagData.data.footDiv.methodBox.checkDeliveryAmountBtnLabel) {
          this.checkDeliveryAmountBtnLabel = this.tagData.data.footDiv.methodBox.checkDeliveryAmountBtnLabel;
        }

        if (this.tagData.data.footDiv.methodBox.checkDeliveryAmountBtnCssStyle) {
          this.checkDeliveryAmountBtnCssStyle = this.tagData.data.footDiv.methodBox.checkDeliveryAmountBtnCssStyle;
        }

        if (this.tagData.data.footDiv.methodBox.deliveryAmount) {
          this.deliveryAmount = this.tagData.data.footDiv.methodBox.deliveryAmount;
        }
        this.showCheckDeliveryAmountBtn = true;
      }

      if (this.tagData && this.tagData.data && this.tagData.data.footDiv && this.tagData.data.footDiv.methods) {
        let methods = this.tagData.data.footDiv.methods;
        for (let index = 0; index < methods.length; index++) {
          const element = methods[index];
          if (element.selected) {
            this.currentMethod = element.value;
            this.currentMethodLabel = element.label;
            if (element.firstRowLeft && element.firstRowLeft.goods_inventory !== undefined) {
              this.goods_inventory = element.firstRowLeft.goods_inventory;
            }
            if (element.firstRowLeft && element.firstRowLeft.pic_url !== undefined) {
              this.pic_url = element.firstRowLeft.pic_url;
            }
            if (element.firstRowLeft && element.firstRowLeft.spec_name !== undefined) {
              this.spec_name = element.firstRowLeft.spec_name;
            }
            if (element.firstRowLeft && element.firstRowLeft.goods_brand_name !== undefined) {
              this.goods_brand_name = element.firstRowLeft.goods_brand_name;
            }
            if (element.firstRowLeft && element.firstRowLeft.price !== undefined) {
              this.price = element.firstRowLeft.price;
            }
            if (element.firstRowLeft && element.firstRowLeft.cost_price !== undefined) {
              this.cost_price = element.firstRowLeft.cost_price;
            }

            break;
          }
        }
      }
    } else {

    }

    if (this.tagData.data.footDiv
      && this.tagData.data.footDiv.submitButton
      && this.tagData.data.footDiv.submitButton.submit
      && this.tagData.data.footDiv.submitButton.submit.label
    ) {
      this.footBtnLabel = this.tagData.data.footDiv.submitButton.submit.label;
    }

    if (this.tagData.data.footDiv.methodBox && this.tagData.data.footDiv.methodBox.isNumberInputDisabled !== undefined) {
      if (!this.tagData.data.footDiv.methodBox.isNumberInputDisabled
        || this.tagData.data.footDiv.methodBox.isNumberInputDisabled === 'false') {
        this.isNumberInputDisabled = false;
        this.disableAdd = false;
        this.disableSub = false;
      } else {
        this.isNumberInputDisabled = true;
        this.disableAdd = true;
        this.disableSub = true;
      }
    }

    // 检查开关已经打开
    if (this.enableCheckDeliveryAmount) {
      this.checkDeliveryAmount();
    }
  }

  // 2024.06.27新增检查起送金额
  checkDeliveryAmount() {
    if (this.currentMoney) {
      let money = parseFloat(this.currentMoney);
      this.showCheckDeliveryAmountBtn = (money * this.postNumber <  parseFloat(this.deliveryAmount));
    }
  }

  async closeModal(type?) {
    const modal = await this.modalController.getTop();
    if (modal) {
      if (type !== undefined) {
        (await modal).dismiss('success');
      } else {
        this.modalController.dismiss({
          dismissed: true
        });
      }

    }
  }
  postData(item?) {
    const that = this;

    if (this.tagData.data && this.tagData.data.footDiv
      && this.tagData.data.footDiv.methodBox
      && this.tagData.data.footDiv.methodBox.isValidData) {
      if (this.tagData.data.footDiv.methodBox.selectSpecHint && this.currentId === undefined) {
        this.appGlobalService.showToast(this.tagData.data.footDiv.methodBox.selectSpecHint, 1500, 'bottom');
        return;
      } else if (this.tagData.data.footDiv.methodBox.selectDeliveryMethod && this.currentMethodLabel === undefined) {
        this.appGlobalService.showToast(this.tagData.data.footDiv.methodBox.selectDeliveryMethod, 1500, 'bottom');
        return;
      }
    }

    let submitButton;
    let submit;
    let successlink;
    if (item) { // 2024.04.03  加入购物车 和 立即购买 两个按钮并列
      submitButton = item;
      submit = item.submit;
      successlink = item.successlink;
    } else {
      submitButton = this.tagData.data.footDiv.submitButton;
      submit = this.tagData.data.footDiv.submitButton.submit;
      successlink = this.tagData.data.footDiv.submitButton.successlink;
    }
    if (submit) {
      const params = submit;
      params.content.count = this.postNumber;
      submit.sessionId = localStorage.getItem('sessionId');
      // 1.6.29 新增属性隐藏1.6.20版本校验选择规格
      if (params.content['hidenValidGoodsId'] === undefined && params.content['goods_id'] !== this.currentId) {
        params.content['shop_goods_sepc_id'] = this.currentId;

      }


      // 2.2.3 新增自动解析经纬度解析
      if (params.content['longitude'] !== undefined
        && params.content['latitude'] !== undefined
        && params.content['need_code'] !== undefined
      ) {

        let paramsPointLng;
        let paramsPointLat;
        let positionInfo
        if (localStorage.getItem('currentCityPosition')) {
          positionInfo = JSON.parse(localStorage.getItem('currentCityPosition'));
        } else if (localStorage.getItem('position')) {
          positionInfo = JSON.parse(localStorage.getItem('position'));
        }
        if (params.content['useParamsPoints'] === undefined) {
          if (positionInfo && positionInfo.center && positionInfo.center.lng && positionInfo.center.lat) {
            params.content['longitude'] = positionInfo.center.lng;
            params.content['latitude'] = positionInfo.center.lat;
            paramsPointLng = positionInfo.center.lng;
            paramsPointLat = positionInfo.center.lat;
          } else {
            paramsPointLng = params.content['longitude'];
            paramsPointLat = params.content['latitude'];
          }
        } else {
          paramsPointLng = params.content['longitude'];
          paramsPointLat = params.content['latitude'];
        }
        this.baiduApiService.getSurroundingPoisByPoint((result) => {
          const [codeResult] = AddressParse.parse(result.address, true);
          params.content['district_code'] = codeResult.code;
          that.actionSubmit(submitButton, item, successlink, params, submit);
        }, paramsPointLng, paramsPointLat);

      } else {
        that.actionSubmit(submitButton, item, successlink, params, submit);
      }

      // else if (params.content['shop_goods_sepc_id'] === '') { // 蜂喔1.9.20商城版本新增 
      //   let data = this.tagData.data.data;
      //   for (let index = 0; index < data.length; index++) {
      //     const ele = data[index];
      //     if (ele.firstRowLeft && ele.firstRowLeft.selected) {
      //       params.content['shop_goods_sepc_id'] = ele.id;
      //       break;
      //     }
      //   }
      // }

    }
  }


  actionSubmit(submitButton, item, successlink, params, submit) {
    let that = this;
    // 1.9.20 蜂喔商城版本新增提货方式
    if (this.tagData.data.footDiv.submitButton && this.tagData.data.footDiv.submitButton.paramName) {
      if (this.currentMethod) {
        params.content[this.tagData.data.footDiv.submitButton.paramName] = this.currentMethod;
      }
    } else if (item && item.paramName) { // 2024.04.03  加入购物车 和 立即购买 两个按钮并列
      if (this.currentMethod) {
        params.content[item.paramName] = this.currentMethod;
      }
    }

    if (this.tagData.data.footDiv.methodBox && this.tagData.data.footDiv.methodBox.checkParam) {
      if (this.goods_inventory !== undefined && this.goods_inventory !== "") {
        params.content['goods_inventory'] = this.goods_inventory;
      }
      if (this.pic_url !== undefined && this.pic_url !== "") {
        params.content['pic_url'] = this.pic_url;
      }
      if (this.spec_name !== undefined && this.spec_name !== "") {
        params.content['spec_name'] = this.spec_name;
      }

      if (this.goods_brand_name !== undefined && this.goods_brand_name !== "") {
        params.content['goods_brand_name'] = this.goods_brand_name;
      }
      if (this.price !== undefined && this.price !== "") {
        params.content['price'] = this.price;
      }
      if (this.cost_price !== undefined && this.cost_price !== "") {
        params.content['cost_price'] = this.cost_price;
      }
    } else {
      if (this.goods_inventory !== undefined) {
        params.content['goods_inventory'] = this.goods_inventory;
      }
      if (this.pic_url !== undefined) {
        params.content['pic_url'] = this.pic_url;
      }
      if (this.spec_name !== undefined) {
        params.content['spec_name'] = this.spec_name;
      }

      if (this.goods_brand_name !== undefined) {
        params.content['goods_brand_name'] = this.goods_brand_name;
      }
      if (this.price !== undefined) {
        params.content['price'] = this.price;
      }
      if (this.cost_price !== undefined) {
        params.content['cost_price'] = this.cost_price;
      }
    }









    // 修复bug防止用户在接口还没处理完成前快速返回到首页
    this.http.post('application/submit', params, res => {
      if (res.success) {

        //1.6.33 新增参数 count
        if (submitButton.isUseReturnCount === '1') {
          if (res.data.eventResult !== undefined) {
            this.appGlobalService.shopGoodsSecondGlobalCountLabel = res.data.eventResult;
          }
        }

        if (successlink) {
          setTimeout(() => {
            if (res.data && res.data.eventResult) {
              successlink.link.params[successlink.link.params.eventResult] = res.data.eventResult;
            }
            that.pageModalService.openPage(successlink.link);
          }, 500);
          if (successlink.link && successlink.link.params && successlink.link.params.shop_ship_address_id) {
            this.appGlobalService.addressEventResultValue = successlink.link.params.shop_ship_address_id;
            this.appGlobalService.shopAddressSelectItemId = successlink.link.params.shop_ship_address_id;
            this.appGlobalService.addressEventResultName = 'shop_ship_address_id';
          } else if (successlink.link && successlink.link.params && successlink.link.params.shop_local_address_id) {
            this.appGlobalService.addressEventResultValue = successlink.link.params.shop_local_address_id;
            this.appGlobalService.shopAddressSelectItemId = successlink.link.params.shop_local_address_id;
            this.appGlobalService.addressEventResultName = 'shop_local_address_id';
            this.appGlobalService.shopAddressSelectItemName = '';
            this.appGlobalService.shopAddressSelectItemLocation = '';
            this.appGlobalService.shopAddressSelectItemPhone = '';
          } else {
            this.appGlobalService.shopAddressSelectItemId = '';  // shopAddressSelectItemId是选择地址页 选择地址后返回上一个页面所需要的地址id参数  走这一段说明没查到 默认地址
          }
        } else {
          if (submit && submit.content && submit.content.disableRefresh === undefined) {
            console.log(new Date().toLocaleString() + '.' + new Date().getMilliseconds() + '  	   ', '  	   ');
            // 修复bug防止用户在接口还没处理完成前快速返回到首页
            this.appGlobalService.reloadCurrentPage(0);
          }


          // 2024.04.11 刷新 购物车商品数量
          if (res.data && res.data.eventResult) {
            if (res.params && res.params.codeEventName) {
              this.eventService.eventEmit.emit(res.params.codeEventName, res);
            } else {
              if ((res.data.eventResult + '').includes(',')) {
                this.pageModalService.chatService.setCartItemCount(res.data.eventResult.split(',')[1],true);
              } else {
                this.pageModalService.chatService.setCartItemCount(res.data.eventResult,true);
              }
            }
          }
        }
        const modal = this.modalController.getTop();
        if (modal) {
          this.modalController.dismiss({
            data: {
              dataType: 'style1',// style1表示从换货商品弹窗返回的， 用于接收方区分
              firstRowValue: this.currentId,
              firstRowLabel: this.currentLabel,
              secondRowValue: this.currentMethod,
              secondRowLabel: this.currentMethodLabel,
              params
            }
          });
        }
        this.appGlobalService.showToast(res.message, 2000, 'middle');

        const spec = {
          label: this.spec_name
        }
        this.eventService.eventEmit.emit('deftSpec', spec);

        if (this.appGlobalService.floatShoppingCartObj['isShow'] === true) {
          let shoppCount;
          shoppCount = res.data.eventResult.split(",")[1];
          this.appGlobalService.floatShoppingCartObj.count = Number(shoppCount);
        }
      } else {
        if (submitButton.isDismissModal === '1') {
          this.closeModal('true');
        }
        // this.modalController.dismiss({}, '', 'NoShowSubmit');
        // const modal = this.modalController.getTop();
        // if (modal) {
        //    modal.dismiss('success');
        // }
        // 2024.01.09 fixed bug
        this.appGlobalService.showToast(res.message, 2000, 'middle');

      }
    });

  }



  selectSpeci(idx, data, item) {
    try {
      if (item.firstRowLeft && item.firstRowLeft.minCount) {
        this.minCount = Number(item.firstRowLeft.minCount);
        this.postNumber = this.minCount;
      }
      if (item.firstRowLeft && item.firstRowLeft.minBatchCount) {
        this.minBatchCount = Number(item.firstRowLeft.minBatchCount);
      }
      for (let index = 0; index < data.length; index++) {
        const ele = data[index];
        if (index === idx) {
          ele.firstRowLeft.selected = true;
          this.currentMoney = ele.firstRowLeft.price;
          this.orginalMoney = ele.firstRowLeft.oldPrice;
          this.currentId = ele.id;
          this.currentLabel = ele.label;
          if (ele.firstRowLeft.goods_inventory !== undefined) {
            this.goods_inventory = ele.firstRowLeft.goods_inventory;
          }
          if (ele.firstRowLeft.pic_url !== undefined) {
            this.pic_url = ele.firstRowLeft.pic_url;
          }
          if (ele.firstRowLeft.spec_name !== undefined) {
            this.spec_name = ele.firstRowLeft.spec_name;
          }
          if (ele.firstRowLeft.goods_brand_name !== undefined) {
            this.goods_brand_name = ele.firstRowLeft.goods_brand_name;
          }
          if (ele.firstRowLeft.price !== undefined) {
            this.price = ele.firstRowLeft.price;
          }
          if (ele.firstRowLeft.cost_price !== undefined) {
            this.cost_price = ele.firstRowLeft.cost_price;
          }
          if (this.postNumber === 0) {
            this.postNumber = 1;
          }
          // 市场价 减去 拿货价  计算省多少钱
          if (this.tagData.data.footDiv.methodBox.commodityPrice !== undefined && this.currentMoney !== undefined && this.orginalMoney !== undefined) {
            this.economicalMoney = (parseFloat(this.orginalMoney) - parseFloat(this.currentMoney)).toFixed(2);
          }
          // 计算利润
          if (this.tagData.data.footDiv.methodBox.profit !== undefined && this.orginalMoney !== undefined && this.currentMoney !== undefined) {
            this.economicalMoney = (parseFloat(this.currentMoney) - parseFloat(this.orginalMoney)).toFixed(2);
          }
          if (document.getElementById('spanSpeci' + idx)) {
            this.addClass(document.getElementById('spanSpeci' + idx), 'spanBtnCheck');
            this.removeClass(document.getElementById('spanSpeci' + index), 'spanBtnUnCheck');
          }
          // if (document.getElementById('specilIcon')) {
          document.getElementById('specilIcon').setAttribute('src', ele.firstRowLeft.img);
          // }
        } else {
          ele.firstRowLeft.selected = false;
          if (document.getElementById('spanSpeci' + index)) {
            this.addClass(document.getElementById('spanSpeci' + idx), 'spanBtnUnCheck');
            this.removeClass(document.getElementById('spanSpeci' + index), 'spanBtnCheck');
          }
        }
      }
    } catch (error) {

    }
  }

  selectMethod(idx, data) {
    try {
      for (let index = 0; index < data.length; index++) {
        const ele = data[index];
        if (index === idx) {
          if (ele && ele.value) {
            this.currentMethod = ele.value;
            this.currentMethodLabel = ele.label;

          }
          if (document.getElementById('spanMethod' + idx)) {
            this.addClass(document.getElementById('spanMethod' + idx), 'spanBtnCheck')
          }
        } else {
          if (document.getElementById('spanMethod' + index)) {
            this.removeClass(document.getElementById('spanMethod' + index), 'spanBtnCheck');
          }
        }
      }
    } catch (error) {

    }
  }

  sub(event, index) {
    event.stopPropagation();
    if (index === 0) {
      // 1.6.34 新增
      if (this.postNumber === this.minCount) {
        this.disableSub = false;
        this.disableAdd = false;
        this.inputReadOnly = true;
        return;
      }
      if (this.postNumber === 0) {
        this.disableSub = true;
        this.disableAdd = false;
        this.inputReadOnly = true;
      } else if (this.postNumber === 1) {
        this.disableSub = true;
      } else {
        this.disableSub = false;
        this.disableAdd = false;
        this.inputReadOnly = true;
        // 如果有 起批量
        if (this.minBatchCount) {
          if (this.postNumber <= this.minCount) {
            this.postNumber = this.minCount;
          } else {
            this.postNumber = this.postNumber - Number(this.minBatchCount);
          }
        } else {
          this.postNumber = this.postNumber - 1;
        }
      }
    } else if (index === 1) {
      let tempMax = this.numberMax;
      if (this.tagData.data.footDiv.number && this.tagData.data.footDiv.number.max) {
        tempMax = this.tagData.data.footDiv.number.max;
      }
      // 新增最低认购数量
      if (this.postNumber >= tempMax) {
        this.disableAdd = true;
        this.disableSub = false;
        this.inputReadOnly = true;
      } else {
        this.disableAdd = false;
        this.inputReadOnly = true;
        this.disableSub = false;
        // 如果有 起批量
        if (this.minBatchCount) {
          this.postNumber = this.postNumber + Number(this.minBatchCount);
        } else {
          this.postNumber = this.postNumber + 1;
        }
      }
    }

    if (this.enableCheckDeliveryAmount) {
      this.checkDeliveryAmount();
    }

  }

  changeValue(event) {
    event.stopPropagation();
  }

  inputValue(e) {
    e.stopPropagation();
    this.postNumber = Number(this.postNumber);
    if (this.postNumber > 0) {
      if (this.tagData.data.footDiv.number && this.tagData.data.footDiv.number.max) {
        let tempMax;
        tempMax = this.tagData.data.footDiv.number.max;
        if (this.postNumber > tempMax) {
          this.postNumber = tempMax;
          this.disableAdd = true;
          this.disableSub = false;
          return;
        }
      }
      // 最低起购量 minCount    起批量 minBatchCount
      if (this.minCount && this.minBatchCount) {
        if (this.postNumber < this.minCount || (this.postNumber - this.minCount) % this.minBatchCount !== 0) {
          this.postNumber = this.minCount;
          this.appGlobalService.showToast('购买数量不符，请通过点击加减数量', 2000, 'middle');
          return;
        }
      }
    } else if (this.postNumber < 0) {
      // 最低起购量 minCount    起批量 minBatchCount
      if (this.minCount && this.minBatchCount) {
        this.postNumber = this.minCount;
        this.appGlobalService.showToast('购买数量不符，请通过点击加减数量', 2000, 'middle');
      } else {
        this.postNumber = 1;
      }
      this.disableAdd = false;
      this.disableSub = true;
    }


    if (this.postNumber === null || this.postNumber <= 0) {
      // 如果有 最低订购数量
      if (this.minCount) {
        this.postNumber = Number(this.minCount);
      }
    }

    // 检查开关已经打开
    if (this.enableCheckDeliveryAmount) {
      this.checkDeliveryAmount();
    }
  }

  addClass(ele, value) {
    if (value) {
      let curValue = this.getClass(ele);
      if (curValue.indexOf(value) === -1) {
        curValue = curValue + " " + value;
      }
      ele.setAttribute("class", curValue.trim());
    }
  }
  getClass(elem) {
    return elem.getAttribute && elem.getAttribute("class") || "";
  }
  removeClass(ele, value) {
    if (value) {
      let curValue = this.getClass(ele);
      if (curValue.indexOf(value) > -1) {
        curValue = (" " + curValue + " ").replace(" " + value + " ", " ");
      }
      ele.setAttribute("class", curValue.trim());
    }
  }
  hasClass(ele, value) {
    let has = false;
    if (value) {
      const curValue = this.getClass(ele);
      if (curValue.indexOf(value) > -1) {
        has = true;
      }
    }
    return has;
  }
}
